package com.hengxinguotong.zhihuichengjian.ui.tower.data;

import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.TowerHistory;
import com.hengxinguotong.zhihuichengjian.ui.BaseActivity;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/24
 *
 * 塔吊历史数据详情
 */

public class TowerHistoryDetailActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.title_tv)
    HXTextView titleTv;
    @BindView(R.id.upload_time)
    HXTextView uploadTime;
    @BindView(R.id.height)
    HXTextView height;
    @BindView(R.id.range)
    HXTextView range;
    @BindView(R.id.rotation)
    HXTextView rotation;
    @BindView(R.id.current_load)
    HXTextView currentLoad;
    @BindView(R.id.current_allow_load)
    HXTextView currentAllowLoad;
    @BindView(R.id.load_percent)
    HXTextView loadPercent;
    @BindView(R.id.wind_speed)
    HXTextView windSpeed;
    @BindView(R.id.tilt)
    HXTextView tilt;
    @BindView(R.id.height_limited)
    HXTextView heightLimited;
    @BindView(R.id.far_and_near_limited)
    HXTextView farAndNearLimited;
    @BindView(R.id.left_and_right_limited)
    HXTextView leftAndRightLimited;
    @BindView(R.id.load_limited)
    HXTextView loadLimited;
    @BindView(R.id.tilt_limited)
    HXTextView tiltLimited;
    @BindView(R.id.wind_speed_limited)
    HXTextView windSpeedLimited;
    @BindView(R.id.interfer_up_limited)
    HXTextView interferUpLimited;
    @BindView(R.id.interfer_down_limited)
    HXTextView interferDownLimited;
    @BindView(R.id.interfer_forward_limited)
    HXTextView interferForwardLimited;
    @BindView(R.id.interfer_behind_limited)
    HXTextView interferBehindLimited;
    @BindView(R.id.interfer_left_limited)
    HXTextView interferLeftLimited;
    @BindView(R.id.interfer_right_limited)
    HXTextView interferRightLimited;
    @BindView(R.id.collision_up_limited)
    HXTextView collisionUpLimited;
    @BindView(R.id.collision_down_limited)
    HXTextView collisionDownLimited;
    @BindView(R.id.collision_forward_limited)
    HXTextView collisionForwardLimited;
    @BindView(R.id.collision_behind_limited)
    HXTextView collisionBehindLimited;
    @BindView(R.id.collision_left_limited)
    HXTextView collisionLeftLimited;
    @BindView(R.id.collision_right_limited)
    HXTextView collisionRightLimited;

    private TowerHistory towerHistory;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tower_history_detail);
        ButterKnife.bind(this);
        towerHistory = (TowerHistory) getIntent().getSerializableExtra("towerHistory");
        initView();
    }

    private void initView() {
        titleTv.setText(R.string.history_data_detail);

        uploadTime.setText(towerHistory.getTime());
        height.setText(towerHistory.getHeight() + "米");
        range.setText(towerHistory.getExtent() + "米");
        rotation.setText(towerHistory.getAngle() + "度");
        currentLoad.setText(towerHistory.getWeight() + "千克");
        setmText(currentAllowLoad, towerHistory.getCurrentAllowWeight() + "千克", towerHistory.getWeightLimitStatus());//	载重限制状态，0正常，1预警，2报警，3违章
//        currentAllowLoad.setText(towerHistory.getCurrentAllowWeight() + "千克");
        loadPercent.setText(towerHistory.getPercent() + "%");
        windSpeed.setText(towerHistory.getWindSpeed() + "米/秒");
        tilt.setText(towerHistory.getObliquity() + "度");

        setmText(heightLimited, towerHistory.getHeightLimitStatus());//高度限位状态 0正常，1预警，2报警

        switch (towerHistory.getTurnLimitFnStatus()){//幅度回转限位状态（远近），0远近端正常 1近端限位预警 2近端限位报警；3远端限位预警 4远端限位报警
            case 0:
                setmText(farAndNearLimited, "远近端", 0);
                break;
            case 1:
                setmText(farAndNearLimited, "近端", 1);
                break;
            case 2:
                setmText(farAndNearLimited, "近端", 2);
                break;
            case 3:
                setmText(farAndNearLimited, "远端", 1);
                break;
            case 4:
                setmText(farAndNearLimited, "远端", 2);
                break;
        }

        switch (towerHistory.getTurnLimitLrStatus()){//幅度回转限位状态（左右），01左限位预警 02左限位报警 03右限位预警 04右限位报警
            case 0:
                setmText(leftAndRightLimited, "左右端", 0);
                break;
            case 1:
                setmText(leftAndRightLimited, "左端", 1);
                break;
            case 2:
                setmText(leftAndRightLimited, "左端", 2);
                break;
            case 3:
                setmText(leftAndRightLimited, "右端", 1);
                break;
            case 4:
                setmText(leftAndRightLimited, "右端", 2);
                break;
        }

        setmText(loadLimited, towerHistory.getWeightLimitStatus());//	载重限制状态，0正常，1预警，2报警，3违章
        setmText(tiltLimited, "倾斜", towerHistory.getTiltLimitStatus());//倾斜限位状态，0正常，1预警，2报警
        setmText(windSpeedLimited, "风速", towerHistory.getWindSpeedLimitStatus());//风速限位状态，0正常，1预警，2报警
        setmText(interferUpLimited, "上", towerHistory.getInterferenceUpStatus());//干涉上限位状态，0正常，1预警，2报警
        setmText(interferDownLimited, "下", towerHistory.getInterferenceDownStatus());//干涉下限位状态，0正常，1预警，2报警
        setmText(interferForwardLimited, "前", towerHistory.getInterferenceBeforeStatus());//干涉前限位状态，0正常，1预警，2报警
        setmText(interferBehindLimited, "后", towerHistory.getInterferenceAfterStatus());//干涉后限位状态，0正常，1预警，2报警
        setmText(interferLeftLimited, "左", towerHistory.getInterferenceLeftStatus());//干涉左限位状态，0正常，1预警，2报警
        setmText(interferRightLimited, "右", towerHistory.getInterferenceRightStatus());//干涉右限位状态，0正常，1预警，2报警

        setmText(collisionUpLimited, "上", towerHistory.getCollisionUpStatus());//碰撞上限位状态，0正常，1预警，2报警
        setmText(collisionDownLimited, "下", towerHistory.getCollisionDownStatus());//碰撞下限位状态，0正常，1预警，2报警
        setmText(collisionForwardLimited, "前", towerHistory.getCollisionBeforeStatus());//碰撞前限位状态，0正常，1预警，2报警
        setmText(collisionBehindLimited, "后", towerHistory.getCollisionAfterStatus());//碰撞后限位状态，0正常，1预警，2报警
        setmText(collisionLeftLimited, "左", towerHistory.getCollisionLeftStatus());//碰撞左限位状态，0正常，1预警，2报警
        setmText(collisionRightLimited, "右", towerHistory.getCollisionRightStatus());//碰撞右限位状态，0正常，1预警，2报警

    }

    @OnClick({R.id.back_tv})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back_tv:
                finish();
                break;
        }
    }

    private void setmText(HXTextView textView, int status){
        switch (status){
            case 0:
                textView.setText(R.string.normal);
                textView.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                textView.setText(R.string.warning);
                textView.setTextColor(getmColor(R.color.color_FD9D00));
                break;
            case 2:
                textView.setText(R.string.alarm);
                textView.setTextColor(getmColor(R.color.color_F5573F));
                break;
            case 3:
                textView.setText(R.string.violation);
                textView.setTextColor(getmColor(R.color.color_D0021B));
                break;
        }
    }

    private void setmText(HXTextView textView, String text, int status){
        switch (status){
            case 0:
                textView.setText(text + "（正常）");
                textView.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                textView.setText(text + "（预警）");
                textView.setTextColor(getmColor(R.color.color_FD9D00));
                break;
            case 2:
                textView.setText(text + "（报警）");
                textView.setTextColor(getmColor(R.color.color_F5573F));
                break;
            case 3:
                textView.setText(text + "（违章）");
                textView.setTextColor(getmColor(R.color.color_D0021B));
                break;
        }
    }

    private int getmColor(int colorId){
        return getResources().getColor(colorId);
    }

}
